﻿@inherits AntDesignTestBase
@code {
	[Fact]
	public void Renders_basic_checkbox()
	{
		var cut = Render(@<Checkbox>Test</Checkbox>);
		cut.MarkupMatches(
			@<label class="ant-checkbox-wrapper" for:ignore>
				<span class="ant-checkbox">
					<input id:ignore type="checkbox" value="true" class="ant-checkbox-input">
					<span class="ant-checkbox-inner"></span>
				</span>
				<span>Test</span>
			</label>);
	}

	[Fact]
	public void Toggle_basic_checkbox()
	{
		//Arrange
		IRenderedComponent<Checkbox> cut = Render<Checkbox>(@<Checkbox>Test</Checkbox>);
		Checkbox checkboxComponent = cut.Instance;
		var inputElement = cut.Find("[type=checkbox]");
		var oldValue = checkboxComponent.Checked;
		//Act
		inputElement.Change(true);
		
        //Assert
        checkboxComponent.Checked.Should().BeTrue();
		checkboxComponent.Checked.Should().Be(!oldValue);
	}

	[Fact]
	public void Bind_Checked_basic_checkbox()
	{
		//Arrange
		bool isChecked = false;		
		var cut = Render(@<Checkbox @bind-Checked=isChecked>Test</Checkbox>);
		var inputElement = cut.Find("[type=checkbox]");		
		//Act
		inputElement.Change(true);
        //Assert
        isChecked.Should().BeTrue();
	}

	[Fact]
	public void Bind_Value_basic_checkbox()
	{
		//Arrange
		bool isChecked = false;		
		var cut = Render(@<Checkbox @bind-Value=isChecked>Test</Checkbox>);
		var inputElement = cut.Find("[type=checkbox]");		
		//Act
		inputElement.Change(true);
        //Assert
        isChecked.Should().BeTrue();
	}

	[Fact]
	public void Bind_Value_basic_checkbox_initial()
	{
		//Arrange
		bool isChecked = true;		
		var cut = Render(@<Checkbox @bind-Value=isChecked>Test</Checkbox>);
		ITokenList classList = cut.Find("span").ClassList;		
                //Assert		
		classList.Contains("ant-checkbox-checked").Should().BeTrue();
	}

	[Fact]
	public void Bind_Checked_basic_checkbox_initial()
	{
		//Arrange
		bool isChecked = true;		
		var cut = Render(@<Checkbox @bind-Checked=isChecked>Test</Checkbox>);
		ITokenList classList = cut.Find("span").ClassList;		
                //Assert		
		classList.Contains("ant-checkbox-checked").Should().BeTrue();
	}

	[Fact]
	public void Fires_OnChange()
	{
		//Arrange
		bool handlerExecuted = false;
		Action<bool> onChangeHandler = value => { handlerExecuted = true; };
		var cut = Render(@<Checkbox OnChange="onChangeHandler">Test</Checkbox>);
		var inputElement = cut.Find("[type=checkbox]");
		//Act
		inputElement.Change(true);
		//Assert		
		handlerExecuted.Should().BeTrue();
	}

	[Fact]
	public void Shound_Not_Fire_OnChange_initial()
	{
		//Arrange
		bool handlerExecuted = false;
		bool isChecked = true;		
		Action<bool> onChangeHandler = value => { handlerExecuted = true; };
		var cut = Render(@<Checkbox @bind-Value=isChecked OnChange="onChangeHandler">Test</Checkbox>);
	        //Assert		
		handlerExecuted.Should().BeFalse();
	}
}
